# -*- coding:utf-8 -*-

import torndb

import setting
from util import gen_uuid


class GenHotelRoom(object):

    def __init__(self):

        self.db = torndb.Connection(
            host=setting.mysql_host,
            database="hotel",
            user=setting.mysql_user,
            password=setting.mysql_password,
            time_zone="+8:00",
            charset='utf8mb4',
            max_idle_time=900,
            connect_timeout=900
        )

        self.date_list = ["2019-05-26", "2019-05-27", "2019-05-28", "2019-06-01", "2019-06-10", "2019-07-27", "2019-08-01"]

    def _get_hotels(self):
        return self.db.query("select id from t_hotel")

    def insert(self, hotel_id, check_in_date):
        params = {"id": gen_uuid(), "hotel_id": hotel_id, "total_cnt": 10, "sellout_cnt": 0, "check_in_date": check_in_date}
        self.db.execute("insert into t_hotel_room (id, hotel_id, total_cnt, check_in_date, sellout_cnt, create_date, update_date) "
                        "values (%(id)s, %(hotel_id)s, %(total_cnt)s, %(check_in_date)s, %(sellout_cnt)s, now(), now())", **params)

    def gen(self):

        hotels = self._get_hotels()
        for hotel in hotels:
            for s in self.date_list:
                self.insert(hotel.id, s)

if __name__ == '__main__':
    gen = GenHotelRoom()
    gen.gen()